package cc.zzone.domain;

import cc.zzone.util.SpringUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.ibatis.annotations.*;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

/**
 * 平台证明对象
 * 连接某些直播平台，需要对应的认证数据才能获取全部信息
 * 因此该对象用于保存平台证明
 *
 * @author jinzhengze
 * @since 2023年10月15日
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PlatformData implements Serializable {

    @Serial
    private static final long serialVersionUID = 22L;

    private String id;

    private String name;

    private String prove;

    public static platformDataMapper mapper() {
        return SpringUtil.getBean(platformDataMapper.class);
    }

    @Mapper
    public interface platformDataMapper {

        @Select("select * from `platform_data` where `id` = #{id}")
        @Results(id = "result", value = {
                @Result(column = "id", property = "id", id = true),
                @Result(column = "name", property = "name"),
                @Result(column = "prove", property = "prove")})
        PlatformData getData(@Param("id") String id);

        @Select({"select * from `platform_data`"})
        @ResultMap("result")
        List<ChatConf> listData();

        @Insert({"<script>",
                "insert into `platform_data`",
                "(",
                "<if test=\"name != null and name != ''\">`name`,</if>",
                "<if test=\"prove != null\">`prove`,</if>",
                "`id`) values (",
                "<if test=\"name != null and name != ''\">#{name},</if>",
                "<if test=\"prove != null\">#{prove},</if>",
                "#{id})",
                "</script>"})
        Integer insertData(PlatformData data);

        @Update({"<script>",
                "update `platform_data`",
                "<set>",
                "<if test=\"name != null and name != ''\">`name` = #{name},</if>",
                "<if test=\"prove != null\">`prove` = #{prove},</if>",
                "</set>",
                "where `id` = #{id}",
                "</script>"})
        Integer updateData(PlatformData data);

        @Delete({"<script>",
                "delete from `platform_data` where id in",
                "<foreach item='id' collection='array' open='(' separator=',' close=')'>",
                "#{id}",
                "</foreach>",
                "</script>"})
        Integer deleteData(String... ids);
    }
}
